﻿Imports SistemaINCA.Security
Imports SistemaINCA.Models.ViewModels

Namespace Models

    Public Interface IMaterias_Default
        '<Authorize(Roles:="ERA")> _
        'Function GetModelByGroupGrado(IDGroup As Integer) As List(Of GroupGradosMateriasModel)

        '<Authorize(Roles:="ERA")> _
        'Function GetMateriasAutoCompleted(IDGroup As Integer, Max As Integer, parametro As String) As IEnumerable(Of GET_LIST_MATERIAS_NOINCLUIDAS_BYIDGROUP_DATATYPE)

        '<Authorize(Roles:="ERA")> _
        'Function AsociarMateriaAlGroupGrado(IDGroup As Integer, IDMateria As Integer, msgError As String) As Boolean

        '<Authorize(Roles:="ERA")> _
        'Function DeleteAsociacionMateriaAlGroupGrado(IDGroup As Integer, IDMateria As Integer, msgError As String) As Boolean

        '<Authorize(Roles:="ERA")> _
        'Function GetMaterias_ByAsignacion(IDGroup As Integer) As List(Of AsignacionMateriasProfesorModel)
    End Interface

    Partial Public Class SchoolClickDB_Repositorio
        Implements IMaterias_Default

        Public ReadOnly Property IMateriasDefault() As IMaterias_Default
            Get
                Return DirectCast(Me, IMaterias_Default)
            End Get
        End Property

        'Private Function GetModelByGroupGrado(IDGroup As Integer) As System.Collections.Generic.List(Of ViewModels.GroupGradosMateriasModel) Implements IMaterias_Default.GetModelByGroupGrado
        '    Try
        '        Using cnn As New SchoolClickEntities
        '            Dim var = cnn.GET_LIST_MATERIAS_BY_GROUPGRADO(IDGroup).ToList
        '            Return var.Select(Function(m) New GroupGradosMateriasModel With {.No = m.NUM, .IDMateria = String.Format("{0}-{1}", m.ID_MATERIAS, IDGroup), .Materia = m.MATERIA}).ToList
        '        End Using
        '    Catch ex As Exception
        '        Throw New ApplicationException(ex.InnerException.Message)
        '    End Try
        'End Function

        'Private Function GetMateriasAutoCompleted(IDGroup As Integer, Max As Integer, parametro As String) As System.Collections.Generic.IEnumerable(Of GET_LIST_MATERIAS_NOINCLUIDAS_BYIDGROUP_DATATYPE) Implements IMaterias_Default.GetMateriasAutoCompleted
        '    Try
        '        Using cnn As New SchoolClickEntities
        '            Return cnn.GET_LIST_MATERIAS_NOINCLUIDAS_BYIDGROUP(IDGroup, Max, parametro).ToList
        '        End Using
        '    Catch ex As Exception
        '        Throw New ApplicationException(ex.InnerException.Message)
        '    End Try
        'End Function

        'Private Function AsociarMateriaAlGroupGrado(IDGroup As Integer, IDMateria As Integer, msgError As String) As Boolean Implements IMaterias_Default.AsociarMateriaAlGroupGrado
        '    Dim eCompleted As Boolean = False
        '    Using cnn As New SchoolClickEntities
        '        Try
        '            Dim bResult = cnn.INS_ASOCIAR_MATERIA_GROUPGRADOS(IDGroup, IDMateria, _
        '                                                   EncryptationSchoolClick.ToStringInseguro(EncryptationSchoolClick.DesencriptarData(My.Resources.PasswordsEncrypts.ERA_ROL))).Single
        '            If bResult Then
        '                eCompleted = True
        '            Else
        '                msgError = "No se pudo asociar la materia al grupo de grados debido a un problema interno. Por favor vuelva a intentarlo"
        '            End If
        '        Catch ex As EntityCommandExecutionException
        '            msgError = ex.InnerException.Message
        '        Catch ex As Exception
        '            'OPTIONAL: Si existiera un error durante toda la operacion, unicamente la interceptamos y la ignoramos.
        '            'Solo tomaremos el mensaje del error y lo regresaremos en la variable delo mensaje de error
        '            msgError = FormatErrorMessage("Ocurrio un problema al intentar realizar la operación.", ex.Message)
        '        End Try
        '    End Using
        '    Return eCompleted
        'End Function

        'Private Function DeleteAsociacionMateriaAlGroupGrado(IDGroup As Integer, IDMateria As Integer, msgError As String) As Boolean Implements IMaterias_Default.DeleteAsociacionMateriaAlGroupGrado
        '    Dim eCompleted As Boolean = False
        '    Using cnn As New SchoolClickEntities
        '        Try
        '            Dim bResult = cnn.DEL_ASOCIACION_GROUPGRADO_MATERIA(IDGroup, IDMateria, _
        '                                                   EncryptationSchoolClick.ToStringInseguro(EncryptationSchoolClick.DesencriptarData(My.Resources.PasswordsEncrypts.ERA_ROL))).Single
        '            If bResult Then
        '                eCompleted = True
        '            Else
        '                msgError = "No se pudo eliminar la asociación de la materia al grupo de grados debido a un problema interno. Por favor vuelva a intentarlo"
        '            End If
        '        Catch ex As EntityCommandExecutionException
        '            msgError = ex.InnerException.Message
        '        Catch ex As Exception
        '            'OPTIONAL: Si existiera un error durante toda la operacion, unicamente la interceptamos y la ignoramos.
        '            'Solo tomaremos el mensaje del error y lo regresaremos en la variable delo mensaje de error
        '            msgError = FormatErrorMessage("Ocurrio un problema al intentar realizar la operación.", ex.Message)
        '        End Try
        '    End Using
        '    Return eCompleted
        'End Function

        'Private Function GetMaterias_ByAsignacion(IDGroup As Integer) As System.Collections.Generic.List(Of ViewModels.AsignacionMateriasProfesorModel) Implements IMaterias_Default.GetMaterias_ByAsignacion
        '    Try
        '        Using cnn As New SchoolClickEntities
        '            Dim datos = cnn.GET_LIST_MATERIAS_BY_GROUPGRADO(IDGroup).ToList
        '            Return datos.Select(Function(m) New AsignacionMateriasProfesorModel With {.No = m.NUM, .ID = m.ID_MATERIAS, .Materia = m.MATERIA}).ToList
        '        End Using
        '    Catch ex As Exception
        '        Throw New ApplicationException(ex.InnerException.Message)
        '    End Try
        'End Function
    End Class
End Namespace
